package org.jetnuke.entities;

import org.apache.log4j.Logger;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class CalendarEvent implements Comparable {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(CalendarEvent.class);

	private int iD;
	private int uID;
	private String tITLE;
	private String fULLDESC;
	private int tYPE;
	private Date sTART_DATE;
	private Date sTART_TIME;
	private Date dURATION;
	private String lOCATION;
	private int rECURRING;
	private int fREQ;
	private int wF;
	private int wD;
	private int wX;
	private Date eXPIRATION;

	public int getStartHour() {
		if (logger.isDebugEnabled()) {
			logger.debug("getStartHour() - start"); //$NON-NLS-1$
		}

		if (sTART_TIME == null)
			return -1;
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(sTART_TIME);
		int returnint = gc.get(Calendar.HOUR_OF_DAY);
		if (logger.isDebugEnabled()) {
			logger.debug("getStartHour() - end"); //$NON-NLS-1$
		}
		return returnint;
	}

	public int getMonth() {
		if (logger.isDebugEnabled()) {
			logger.debug("getMonth() - start"); //$NON-NLS-1$
		}

		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(sTART_DATE);
		int returnint = gc.get(Calendar.MONTH);
		if (logger.isDebugEnabled()) {
			logger.debug("getMonth() - end"); //$NON-NLS-1$
		}
		return returnint;
	}

	public int getExpirationMonth() {
		if (logger.isDebugEnabled()) {
			logger.debug("getExpirationMonth() - start"); //$NON-NLS-1$
		}

		if (eXPIRATION == null)
			return -1;
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(eXPIRATION);
		int returnint = gc.get(Calendar.MONTH);
		if (logger.isDebugEnabled()) {
			logger.debug("getExpirationMonth() - end"); //$NON-NLS-1$
		}
		return returnint;
	}

	public int getYear() {
		if (logger.isDebugEnabled()) {
			logger.debug("getYear() - start"); //$NON-NLS-1$
		}

		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(sTART_DATE);
		int returnint = gc.get(Calendar.YEAR);
		if (logger.isDebugEnabled()) {
			logger.debug("getYear() - end"); //$NON-NLS-1$
		}
		return returnint;
	}

	public int getExpirationYear() {
		if (logger.isDebugEnabled()) {
			logger.debug("getExpirationYear() - start"); //$NON-NLS-1$
		}

		if (eXPIRATION == null)
			return -1;
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(eXPIRATION);
		int returnint = gc.get(Calendar.YEAR);
		if (logger.isDebugEnabled()) {
			logger.debug("getExpirationYear() - end"); //$NON-NLS-1$
		}
		return returnint;
	}

	public int getDate() {
		if (logger.isDebugEnabled()) {
			logger.debug("getDate() - start"); //$NON-NLS-1$
		}

		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(sTART_DATE);
		int returnint = gc.get(Calendar.DAY_OF_MONTH);
		if (logger.isDebugEnabled()) {
			logger.debug("getDate() - end"); //$NON-NLS-1$
		}
		return returnint;
	}

	public int getExpirationDate() {
		if (logger.isDebugEnabled()) {
			logger.debug("getExpirationDate() - start"); //$NON-NLS-1$
		}

		if (eXPIRATION == null)
			return -1;
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(eXPIRATION);
		int returnint = gc.get(Calendar.DAY_OF_MONTH);
		if (logger.isDebugEnabled()) {
			logger.debug("getExpirationDate() - end"); //$NON-NLS-1$
		}
		return returnint;
	}

	public Date getDURATION() {
		return dURATION;
	}

	public void setDURATION(Date duration) {
		dURATION = duration;
	}

	public Date getEXPIRATION() {
		return eXPIRATION;
	}

	public void setEXPIRATION(Date expiration) {
		eXPIRATION = expiration;
	}

	public int getFREQ() {
		return fREQ;
	}

	public void setFREQ(int freq) {
		fREQ = freq;
	}

	public String getFULLDESC() {
		return fULLDESC;
	}

	public void setFULLDESC(String fulldesc) {
		fULLDESC = fulldesc;
	}

	public int getID() {
		return iD;
	}

	public void setID(int id) {
		iD = id;
	}

	public String getLOCATION() {
		return lOCATION;
	}

	public void setLOCATION(String location) {
		lOCATION = location;
	}

	public int getRECURRING() {
		return rECURRING;
	}

	public void setRECURRING(int recurring) {
		rECURRING = recurring;
	}

	public Date getSTART_DATE() {
		return sTART_DATE;
	}

	public void setSTART_DATE(Date start_date) {
		sTART_DATE = start_date;
	}

	public Date getSTART_TIME() {
		return sTART_TIME;
	}

	public void setSTART_TIME(Date start_time) {
		sTART_TIME = start_time;
	}

	public String getTITLE() {
		return tITLE;
	}

	public void setTITLE(String title) {
		tITLE = title;
	}

	public int getTYPE() {
		return tYPE;
	}

	public void setTYPE(int type) {
		tYPE = type;
	}

	public int getUID() {
		return uID;
	}

	public void setUID(int uid) {
		uID = uid;
	}

	public int getWD() {
		return wD;
	}

	public void setWD(int wd) {
		wD = wd;
	}

	public int getWF() {
		return wF;
	}

	public void setWF(int wf) {
		wF = wf;
	}

	public int getWX() {
		return wX;
	}

	public void setWX(int wx) {
		wX = wx;
	}

	// Comparing based on times, not on dates!
	public int compareTo(Object arg0) {
		if (logger.isDebugEnabled()) {
			logger.debug("compareTo(Object) - start"); //$NON-NLS-1$
		}

		CalendarEvent other = (CalendarEvent) arg0;
		if (sTART_TIME == null) {
			if (other.sTART_DATE != null)
				return -1;

			if (logger.isDebugEnabled()) {
				logger.debug("compareTo(Object) - end"); //$NON-NLS-1$
			}
			return 0;
		}
		if (other.sTART_TIME == null)
			return 1;
		int returnint = this.sTART_TIME.compareTo(other.sTART_TIME);
		if (logger.isDebugEnabled()) {
			logger.debug("compareTo(Object) - end"); //$NON-NLS-1$
		}
		return returnint;
	}
}
